#include "maincontroller.h"

MainController *mainController = NULL;

MainController::MainController(QObject *parent) : QObject(parent)
{

}

MainController::~MainController()
{

}

void MainController::setContentWidget(QStackedWidget *stackedWidget)
{
      contentWidget = stackedWidget;
      assistsettingView = new AssistsettingView();
      communicationSetView = new CommunicationSetView();
      dateTimeSetView = new DateTimeSetView();

      departClinicianView = new DepartClinicianView();
      flagAlarmResponseView = new FlagAlarmResponse();
      gainSettingView = new GainSettingView();
      labInfoSetView = new LabInfoSetView();
      maintaintSetView = new MaintaintSetView();
      paramMicroscopyView = new ParamMicroscopyView();
      paramResearchView = new ParamResearchView();
      paramReferLimitsView = new ParamReferLimitsView();
      paramUnitSetView = new ParamUnitSetView();

      printsettingView = new PrintSettingView();
      reagentManageSetView = new ReagentManageSetView();
      userManagerview = new UserManagerView();
      sampleAnalysisForm = new SampleAnalysisForm();

      manualCalibrationForm = new ManualCalibrationForm();

      contentWidget->addWidget(assistsettingView);
      contentWidget->addWidget(communicationSetView);
      contentWidget->addWidget(dateTimeSetView);
      contentWidget->addWidget(departClinicianView);
      contentWidget->addWidget(flagAlarmResponseView);
      contentWidget->addWidget(gainSettingView);
      contentWidget->addWidget(labInfoSetView);
      contentWidget->addWidget(maintaintSetView);
      contentWidget->addWidget(paramMicroscopyView);
      contentWidget->addWidget(paramResearchView);
      contentWidget->addWidget(paramReferLimitsView);
      contentWidget->addWidget(paramUnitSetView);
      contentWidget->addWidget(printsettingView);
      contentWidget->addWidget(reagentManageSetView);
      contentWidget->addWidget(userManagerview);
      contentWidget->addWidget(sampleAnalysisForm);
      contentWidget->addWidget(manualCalibrationForm);

    sampleAnalysisForm->show();
    contentWidget->setCurrentWidget(sampleAnalysisForm);
}


void MainController::setCurrentWidgetID(WidgetID widgetid)
{
    QWidget *switchToForm = NULL;

    if(widgetid == E_AddDiluentDialog){
        AddDiluent *addDiluent = new AddDiluent();
        addDiluent->showProcessDialog();
        addDiluent->deleteLater();
        return;
    }

    switch(widgetid)
    {
    case E_AssistView:
        switchToForm = (QWidget *)assistsettingView;
        break;
    case E_PrintSetView:
        switchToForm = (QWidget *)printsettingView;
        break;
    case E_FlagAlarmView:
        switchToForm = (QWidget *)flagAlarmResponseView;
        break;
    case E_CommuicationView:
        switchToForm = (QWidget *)communicationSetView;
        break;
    case E_LabInfoSetView:
        switchToForm =(QWidget *)labInfoSetView;
        break;
    case E_DateTimeSetView:
        switchToForm = (QWidget *)dateTimeSetView;
        break;
    case E_UserManagerView:
        switchToForm = (QWidget *)userManagerview;
        break;
    case E_MaintainView:
        switchToForm = (QWidget *)maintaintSetView;
        break;
    case E_ReagManageView:
        switchToForm = (QWidget *)reagentManageSetView;
        break;
    case E_DepartClinicanView:
        switchToForm = (QWidget *)departClinicianView;
        break;
    case E_GainSettingView:
        switchToForm = (QWidget *)gainSettingView;
        break;
    case E_ParamReserachView:
        switchToForm = (QWidget *)paramResearchView;
        break;
    case E_ParamReferLimitsView:
        switchToForm = (QWidget *)paramReferLimitsView;
        break;
    case E_ParamUnitView:
        switchToForm = (QWidget *)paramUnitSetView;
        break;
    case E_ParamMicroscopeView:
        switchToForm = (QWidget *)paramMicroscopyView;
        break;
    case E_SampleAnalysisView:
        switchToForm = (QWidget *)sampleAnalysisForm;
        break;
    case E_ManualCalibrate:
        switchToForm = (QWidget *)manualCalibrationForm;
        break;
    }

    if(switchToForm == NULL)
        return ;

    if(switchToForm->objectName().compare(contentWidget->currentWidget()->objectName()) != 0)
    {
        if(contentWidget->currentWidget()->close() == true)
        {
            contentWidget->setCurrentWidget(switchToForm);
        }
    }
}



MainController *MainController::getInstance(){
    if(mainController == NULL){
        mainController = new MainController();
    }
    return mainController;
}




